package com.cntcdt.api.service.impl;

import java.util.List;

import com.cntcdt.api.db.dao.AdminUserDao;
import com.cntcdt.api.db.model.AdminUserModel;
import com.cntcdt.api.service.AdminUserService;

public class AdminUserServiceImpl implements AdminUserService {

	@Override
	public int insertModel(AdminUserModel addLineUser) {
		return AdminUserDao.getInstance().insert(addLineUser);
	}

	@Override
	public AdminUserModel findByUsername(String username, String password) {
		return AdminUserDao.getInstance().findByUsername(username, password);
	}

	@Override
	public AdminUserModel findById(Integer id) {
		return AdminUserDao.getInstance().findByPrimaryKey(id);
	}

	@Override
	public List<AdminUserModel> findBySortTime(int sortTime) {
		return AdminUserDao.getInstance().findBySortTime(sortTime);
	}

	@Override
	public AdminUserModel findByUsername2(String username) {
		return AdminUserDao.getInstance().findByUsername2(username);
	}

	@Override
	public boolean updateModel(AdminUserModel addLineUser) {
		return AdminUserDao.getInstance().updateAny(addLineUser);
	}

	@Override
	public AdminUserModel findByAccessToken(String accessToken) {
		return AdminUserDao.getInstance().findByAccessToken(accessToken);
	}

	@Override
	public List<AdminUserModel> findByAddLineUser() {
		return AdminUserDao.getInstance().findByAddLineUser();
	}

	@Override
	public AdminUserModel findByIdAndAuthPower(Integer id, int bgType) {
		AdminUserModel adminUser = AdminUserDao.getInstance().findByPrimaryKey(id);
		// 商家后台权限
		if (bgType == 1 && adminUser.getConsociationBg() != 1) {
			return null;
		}
		// 补线后台权限
		else if (bgType == 2 && adminUser.getAddLineBg() != 1) {
			return null;
		}
		// 用户管理权限
		else if (bgType == 3 && adminUser.getUserAdminBg() != 1) {
			return null;
		}
		// 设备升级后台权限
		else if (bgType == 4 && adminUser.getUpdateDeviceBg() != 1) {
			return null;
		}
		// 设备上线后台权限
		else if (bgType == 5 && adminUser.getDeviceMoveApplyBg() != 1) {
			return null;
		}
		// 充电宝管理权限
		else if (bgType == 6 && adminUser.getChongdianbaoBg() != 1) {
			return null;
		}
		// 提现后台权限
		else if (bgType == 7 && adminUser.getPickupMoney() != 1) {
			return null;
		}
		// 合作伙伴申请后台权限
		else if (bgType == 8 && adminUser.getCooperationBg() != 1) {
			return null;
		}
		// 统计后台权限
		else if (bgType == 9 && adminUser.getCntbg() != 1) {
			return null;
		}
		// 用户管理后台权限
		else if (bgType == 10 && adminUser.getLaidianUserBg() != 1) {
			return null;
		}
		return adminUser;
	}

	@Override
	public List<AdminUserModel> findByAdminGroupId(Integer adminGroupId) {
		// TODO Auto-generated method stub
		return AdminUserDao.getInstance().findByAdminGroupId(adminGroupId);
	}

}
